﻿using System;
using MFilesAPI;

namespace FSAG.UserImporter
{
    /// <summary>
    /// Represent the group with all related attributes and implicit converters for creating a userGroup
    /// </summary>
    public class Group
    {
        /// <summary>
        /// The unique ID of the current user
        /// </summary>
        public int GroupID { get; set; }

        /// <summary>
        /// The group name of the current user
        /// </summary>
        public string GroupName { get; set; }

        /// <summary>
        /// Contains a timestamp of the time when the group entity was modified
        /// </summary>
        public string Modified { get; set; }

        /// <summary>
        /// The state (active, deactiv, deleted) of the current group
        /// </summary>
        public State GroupStatus { get; set; }

        /// <summary>
        /// Checks wheter this group was modified
        /// </summary>
        /// <returns>Returns true, if a modified timestamp is set</returns>
        public bool IsModified()
        {
            return !String.IsNullOrWhiteSpace(Modified);
        }

        /// <summary>
        /// Checks wheter this group was deleted
        /// </summary>
        /// <returns>Returns true, if the group is deleted</returns>
        public bool IsDeleted()
        {
            return (GroupID != 0 && GroupStatus == State.Deleted);
        }

        /// <summary>
        /// Checks wheter this group was irrevocabledeleted
        /// </summary>
        /// <returns>Returns true, if the groupname is empty</returns>
        public bool IsIrrevocableDeleted()
        {
            return (string.IsNullOrEmpty(GroupName));
        }

        /// <summary>
        /// Method used to implicitly convert a given group to a userGroup
        /// </summary>
        /// <param name="group">The group instance which should be converted</param>
        /// <returns>Returns the converted group account</returns>
        public static implicit operator UserGroupClass(Group group)
        {
            return new UserGroupClass
            {
                ID = group.GroupID,
                Name = group.GroupName
            };
        }

        /// <summary>
        /// Checks wheter a given object is equals to this object
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>True, if the object is equals</returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }

            return GroupName.Equals(((Group)obj).GroupName);
        }

        /// <summary>
        /// Returns the hascode of this object
        /// </summary>
        /// <returns>Returns the hashcode</returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
